<script>
    import { onMount } from 'svelte';
  
    export let message = '查无此课程，请您再确认一下！';
    export let duration = 3000; // 默认持续时间为 3000 毫秒（3 秒）
  
    let show = false;
  
    onMount(() => {
      show = true;
      setTimeout(() => {
        show = false;
      }, duration);
    });
  </script>
  
  <style>
    .alert {
      padding: 1em;
      background-color: lightblue;
      border: 2px solid rgb(255, 0, 4);
      border-radius: 5px;
      position: fixed;
      top: 25%;
      right: 45%;
      transition: opacity 0.5s;
      opacity: 0;
    }
    .alert.show {
      opacity: 1;
    }
    .alert.hide {
      opacity: 0;
    }
  </style>
  
  <div class="alert {show ? 'show' : 'hide'}">
    {message}
  </div>